//
//  CashVoucherTableVC.m
//  DaoZiJinFu
//
//  Created by woker on 16/6/28.
//  Copyright © 2016年 iwoker. All rights reserved.
//

#import "CashVoucherTableVC.h"
#import "ChooseVoucherCell.h"
#import "VoucherExplainTableVC.h"
#import "VoucherModel.h"

@interface CashVoucherTableVC () {
    NSMutableArray *dataArray;
    NSInteger currentPage;
    NSInteger voucherCount;
}

@end

@implementation CashVoucherTableVC

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setupTitleView:@"现金抵用券"];
    self.view.backgroundColor = BACKGROUND_COLOR;
    [self leftButton:nil];
    [self rightButton];
    _rightImage.image = IMAGE(@"优惠卷说明");
    dataArray = [NSMutableArray array];
    
    JSVIEWSHOW;
    DZRequestUtil *request = [[DZRequestUtil alloc] init];
    request.requestUrl = @"User/getCouponList";
    request.params = @{@"pagesize":@100};
    [DZNetAPI request:request success:^(id response) {
        NSLog(@"%@",response);
        DZResponse *model = [DZResponse mj_objectWithKeyValues:response];
        JSVIEWHIDE;
        if (model.rt == 1) {
            voucherCount = [model.data[@"count"] integerValue];
            for (NSDictionary *tempDic in model.data[@"list"]) {
                VoucherModel *model = [VoucherModel modelWithDict:tempDic];
                [dataArray addObject:model];
            }
            [self.tableView reloadData];
        }else{
            JSSHOW(model.msg);
        }
    } failure:^(NSError *error) {
        JSVIEWHIDE;
        JSSHOW(LOAD_FAIL_TIP);
    }];
}

- (void)rightBarItemOnClick:(id)sender {
    VoucherExplainTableVC *voucherExplain = [[VoucherExplainTableVC alloc] init];
    [self.navigationController pushViewController:voucherExplain animated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return [dataArray count];
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 50*(SCREEN_WIDTH-24)/150+16;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return 1;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    return 1;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView registerNib:[UINib nibWithNibName:@"ChooseVoucherCell" bundle:nil] forCellReuseIdentifier:CHOOSEVOUCHER_CELL];
    ChooseVoucherCell *cell = [ChooseVoucherCell cellWithTableView:tableView];
    [cell setUpCellWithModel:dataArray[indexPath.row]];
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
   
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
  
}

@end
